package com.littlebee.storychild.common.utils;

import android.webkit.MimeTypeMap;

/**
 * @author liaoyong
 * @desc 功能描述
 * @date 2016/1/4 16:07
 */
public class MimeTypeUtil {

    private MimeTypeUtil(){

    }


    public static String getMimeTypeForHttp(final String fileName){
        //ByteArrayStream类型
        String result = "application/octet-stream";
        int suffixPostion = fileName.lastIndexOf(".");
        if(suffixPostion != -1){
            String suffix = fileName.substring(suffixPostion + 1);
            result = MimeTypeMap.getSingleton().getMimeTypeFromExtension(suffix);
        }
        return result;
    }

    /**
     * 根据文件名(Simple或者Absolute都可以)得到它的Mime类型，如image/png
     *
     * @param fileName
     * @return
     */
    public static String getMimeTypeFromFileName(String fileName) {
        String extension = MimeTypeMap.getFileExtensionFromUrl(fileName);
        return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
    }

}
